package com.erp.system.service.impl;

import com.erp.system.domain.Material;
import com.erp.system.mapper.MaterialMapper;
import com.erp.system.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * FileName: MaterialServiceImpl.java
 * 业务层接口实现类的详细说明
 *
 * @author 类创建者姓名
 * @version 1.00
 * @Date 创建日期
 */
@Service
public class MaterialServiceImpl implements MaterialService {

    @Autowired
    private MaterialMapper materialMapper;


    @Override
    public List<Material> queryAll(Material material) {
        return materialMapper.queryAll(material);
    }

    @Override
    public List<Material> queryByIds(String[] ids) {
        return materialMapper.queryByIds(ids);
    }

    @Override
    public int insertMaterial(Material material) {
        return materialMapper.insertMaterial(material);
    }

    @Override
    public List<Material> queryCode(String code) {
        return materialMapper.queryCode(code);
    }

    @Override
    public int deleteMaterialByIds(String[] id) {
        return materialMapper.deleteMaterialByIds(id);
    }

    @Override
    public Material queryById(String id) {
        return materialMapper.queryById(id);
    }

    @Override
    public int updateMaterial(Material material) {
        return materialMapper.updateMaterial(material);
    }

    @Override
    public boolean checkCodeUnique(Material material) {
        Material param = new Material();
        param.setCode(material.getCode());
        List<Material> list = queryAll(param);
        return !list.isEmpty() && list.stream().noneMatch(m -> m.getId().equals(material.getId()));
    }
}
